package com.mindskip.xzs.controller.admin;

import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.service.DepartmentService;
import com.mindskip.xzs.viewmodel.IdNameKV;
import com.mindskip.xzs.viewmodel.admin.dept.DeptTreeRes;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author artka
 * @description:
 * @date 2022/9/16 10:58 PM
 */
@RestController("DeptController")
@RequestMapping(value = "/api/admin/dept")
public class DeptController {

    @Resource
    private DepartmentService departmentService;

    /**
     * 获取部门树
     */
    @GetMapping("/tree")
    public RestResponse<DeptTreeRes> queryTree() {
        return RestResponse.ok(departmentService.queryDeptTree());
    }

    /**
     * 查询部门kv列表
     */
    @RequestMapping(value = "/list/kv", method = RequestMethod.GET)
    public RestResponse<List<IdNameKV>> selectDeptKV(@RequestParam(required = false, value = "keyword") String keyword) {
        return RestResponse.ok(departmentService.queryDeptKVListInCache(keyword));
    }

    /**
     * 查询部门kv列表
     */
    @RequestMapping(value = "/list/user/kv", method = RequestMethod.GET)
    public RestResponse<List<IdNameKV>> selectDeptKV(@RequestParam(required = false, value = "userId") Integer userId) {
        return RestResponse.ok(departmentService.queryUserDeptKV(userId));
    }
}
